package com.ruoyi.project.tugboat.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.tugboat.domain.CPoint;
import com.ruoyi.project.tugboat.service.ICPointService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 测点Controller
 * 
 * @author ruoyi
 * @date 2023-12-14
 */
@RestController
@RequestMapping("/system/point")
public class CPointController extends BaseController
{
    @Autowired
    private ICPointService cPointService;

    /**
     * 查询测点列表
     */
    @PreAuthorize("@ss.hasPermi('system:point:list')")
    @GetMapping("/list")
    public TableDataInfo list(CPoint cPoint)
    {
        startPage();
        List<CPoint> list = cPointService.selectCPointList(cPoint);
        return getDataTable(list);
    }

    /**
     * 导出测点列表
     */
    @PreAuthorize("@ss.hasPermi('system:point:export')")
    @Log(title = "测点", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CPoint cPoint)
    {
        List<CPoint> list = cPointService.selectCPointList(cPoint);
        ExcelUtil<CPoint> util = new ExcelUtil<CPoint>(CPoint.class);
        util.exportExcel(response, list, "测点数据");
    }

    /**
     * 获取测点详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:point:query')")
    @GetMapping(value = "/{pointId}")
    public AjaxResult getInfo(@PathVariable("pointId") Long pointId)
    {
        return success(cPointService.selectCPointByPointId(pointId));
    }

    /**
     * 新增测点
     */
    @PreAuthorize("@ss.hasPermi('system:point:add')")
    @Log(title = "测点", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CPoint cPoint)
    {
        return toAjax(cPointService.insertCPoint(cPoint));
    }

    /**
     * 修改测点
     */
    @PreAuthorize("@ss.hasPermi('system:point:edit')")
    @Log(title = "测点", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CPoint cPoint)
    {
        return toAjax(cPointService.updateCPoint(cPoint));
    }

    /**
     * 删除测点
     */
    @PreAuthorize("@ss.hasPermi('system:point:remove')")
    @Log(title = "测点", businessType = BusinessType.DELETE)
	@DeleteMapping("/{pointIds}")
    public AjaxResult remove(@PathVariable Long[] pointIds)
    {
        return toAjax(cPointService.deleteCPointByPointIds(pointIds));
    }
}
